import docker
import docker_util

# 请将image_name修改为自己创建的私有Registry镜像全名称
image_name = '192.168.0.33:5000/kp-base-notebook:1.0'
service_name = 'lab-jerry'
mount_host_path = '/data/jerry'

# (1) 检查是否有以'jerry'名称存在的Service
found_name = 'jerry'
found_services = docker_util.find_services(found_name)
if len(found_services) == 0:
    print("No service with ", found_name)
else :
    print("Service found with ", found_name, ":")
    for service in found_services:
        print(service)
print("=================================")

# (2) 确保lab-jerry服务被删除，以便稍后能创建同名服务
docker_util.remove_service(service_name)

# (3) 创建Service
result = docker_util.create_service(service_name, image_name, mount_host_path)
if result:
    print("service ", service_name, " created successfully.")
    print("=================================")

# (4) 获取映射的端口号
state, port = docker_util.get_service_port(service_name)
print("Service port: ", port)
print("=================================")

# (5) 清除服务
docker_util.remove_service(service_name)
print("Service removed")
